﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Admx_Generator.Exceptions
{
    public class DuplicateNamespaceException:Exception
    {
        private System.Resources.ResourceManager resMan = new System.Resources.ResourceManager("Admx_Generator.Localization.LocalizedStrings", typeof(DuplicateNamespaceException).Assembly);
        private string _message = String.Empty;

        /// <summary>
        /// Create a new instance of the DuplicateNamespaceException. This Exception is throw when trying to add a new Namespace to a Project that already have this Namespace.
        /// </summary>
        /// <param name="duplicateNamespace">The Namespace that have caused this Exception</param>
        public DuplicateNamespaceException(Namespace duplicateNamespace)
        { this._message = this.GetLocalizedString("DuplicateNamespaceExceptionMessage") + "[" +duplicateNamespace.Prefix + ":" + duplicateNamespace.Target + "]"; }

        public override string Message
        {
            get
            {
                return this._message;
            }
        }

        /// <summary>
        /// Returns a localized string depending of the current culture.
        /// </summary>
        /// <param name="unlocalizedString">string to localized.</param>
        /// <returns>the localized string.</returns>
        protected string GetLocalizedString(string unlocalizedString)
        {
            string result = string.Empty;

            try
            {
                result = resMan.GetString(unlocalizedString);
                if (!string.IsNullOrEmpty(result))
                    return result;
            }
            catch (Exception) { }

            return "Missing_Localized_String_For(" + ((unlocalizedString != null) ? unlocalizedString : "null") + ")";
        }
    }
}
